
@extends ('layouts/app')

@section('content')
    <div class="weui-panel hui-bg">
        <form name="info" id="info" method="POST">
            @csrf
            <div class="cadr">

            </div>
            <div class="weui-panel__ft frame">
                <a href="/mobile/business" class="frame-h weui-cell_access weui-cell_link">
                    <svg class="icon f80 gary9" >
                        <use xlink:href="#icon-weibiaoti--28 "></use>
                    </svg>
                </a>
            </div>
        </form>
    </div>
    <script>
        var _token = $("input[name='_taken']").val();

        // 获取银行卡列表
        function getBankList () {
            $.post("/api/shop/showCard", {_token: _token}, function (res) {

                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                console.log("666", res);
                var data = {};
                data['type'] = 'bankList';
                data['element'] = '.cadr';
                data['data'] = res.data;

                A.init(data);
            });
        }

        getBankList();

        // 长按删除银行卡
        function delBank(id) {
            $.post("/api/shop/deleteCard", {_token: _token, id: id}, function (res) {
                if (typeof res === 'string') {
                    res = JSON.parse(res);
                }
                // 删除成功
                if (res.code == 200) {
                    $.toast(res.info, 'text', function () {
                        // 刷新当前页面
                        location.reload();
                    });
                }
            });
        }


        // 长按银行卡事件
        $(".cadr").on("mousedown touchstart", "a", function () {
            var id = $(this).attr("id");
            // 长按删除银行卡
            holdDown(function () {
                $.confirm("我要删除当前银行卡!", function(){
                    // 如果点击确定,就删除
                    delBank(id);
                },function () {
                    console.log("取消");
                });
            });
        }).on("mouseup touchend", 'a', function () {
            holdUp();

        });
    </script>
@endsection

